package com.publicClass;

import com.JR.GetDate;
import com.util.interfaces.Id;

import java.util.Date;
import java.util.List;

public class JRCRUD<T> {
    //根据ID查看某条数据
    public <T extends Id> T show(int id, List<T> ts){
        for (T t: ts){
            if (t.getId() == id){
                System.out.println(t.toString());
                return t;
            }
        }
        return null;
    }
    //查看所有数据
    public  void show(List<T> list){
        for (T t:list){
            System.out.println(t.toString());
        }
    }
    //根据创建时间Date查找
    public <T extends GetDate> void show(Date date, List<T> ts){
        for (T t: ts){
            if (t.getDate() == date){
                System.out.println(t.toString());
            }
        }
    }
    //根据ID删除某条数据
    public <T extends Id> boolean delet(int id,List<T> ts){
        int i = 0;
        for (T t: ts){
            i++;
            if (t.getId() == id){
                ts.remove(i);
                return true;
            }
        }
        return false;
    }
    //根据创建时间Date删除
    public <T extends GetDate> boolean delet(Date date,List<T> ts){
        int i = 0;
        for (T t: ts){
            i++;
            if (t.getDate() == date){
                ts.remove(i);
                return true;
            }
        }
        return false;
    }
    //删除所有数据
    public  void delete(List<T> ts){
        int i = 0;
        while(ts != null){
            ts.remove(i);
            i++;
        }
    }
    //修改(内容由外界修改)
    public <T extends Id> void delet(int id,List<T> ts,T t){
        int i = 0;
        for (T t1: ts){
            i++;
            if (t1.getId() == id){
                ts.add(i,t);
            }
        }
    }
    //增加
    public boolean insert(List<T> ts,T t){
        ts.add(t);
        return true;
    }
    //批量添加
}
